package event.timerevent;

import java.util.Vector;

class TimerManager {

	private Object Source;
	private Vector<TimerListener> Listeners;
	
	protected TimerManager(Object source){
		this.Source=source;
		this.Listeners=new Vector<TimerListener>(0,1);
	}
	
	protected boolean addTimerListener(TimerListener TL){
		return this.Listeners.add(TL);
	}
	protected boolean removeTimerListener(TimerListener TL){
		return this.Listeners.remove(TL);
	}
	@SuppressWarnings("unchecked")
	protected void sendTimerEvent(int typeevent,int lapsdone){
		TimerEvent TE=new TimerEvent(this.Source,lapsdone);
		Vector<TimerListener> ListenerCopy=(Vector<TimerListener>)this.Listeners.clone();
		switch (typeevent){
			case Timer.ACTIVE:{/*il timer ha raggiunto il numero di giri prestabilito e deve mandare il TimerRung*/
				for (int i=0;i<ListenerCopy.size();i++){
					ListenerCopy.elementAt(i).TimerRung(TE);
				}
			break;
			}
			case Timer.PAUSE: {/*il timer e' stato messo in pause e deve mandare il TimerPaused*/
				for (int i=0;i<ListenerCopy.size();i++){
					ListenerCopy.elementAt(i).TimerPaused(TE);
				}
			break;
			}
			case Timer.SUSPENDED: {/*il timer e' stato sospeso e deve mandare TimerSuspended*/
				for (int i=0;i<ListenerCopy.size();i++){
					ListenerCopy.elementAt(i).TimerSuspended(TE);
				}
			}
		}
		
	}
}
